﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LogIn_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString.ToString());
        con.Open();
        SqlCommand cmd = new SqlCommand("select COUNT(*)FROM Register WHERE Name='" + UserNames.Text + "' and Password='" + Passwords.Text + "'", con);
        int OBJ = Convert.ToInt32(cmd.ExecuteScalar());
        if (OBJ > 0)
        {
            Session["name"] = UserNames.Text;
            Response.Redirect("Home.aspx");
        }
        else
        {
            Label1s.Text = "Invalid username or password";
            //this.Label1.ForeColor = Color.Red;
        }
    }
}